package org.example.loggingservice.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.example.loggingservice.entity.OperationLog;
import org.example.loggingservice.mapper.LogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RocketMQMessageListener(
        consumerGroup = "log-consumer-group",
        topic = "operation-log-topic"
)
public class LogConsumer implements RocketMQListener<OperationLog> {

    @Autowired
    private LogMapper logMapper;

    @Override
    public void onMessage(OperationLog operationLog) {
        log.info(" 接收到日志消息: {}", operationLog);
        logMapper.insert(operationLog);
    }
}
